﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPI.OrganizationDomain.Model.Entity;
using KPI.OrganizationDomain.Model.RepositoryInterface;
using KPI.OrganizationDomain.Model.ValueObject;
using KPI.ServiceInterface;
using KPI.Utility;
using System.Data;

namespace KPI.OrganizationDomain.Service
{
    public class OrganizationService : IOrganizationService
    {
        private IOrganizationRepository _repository;

        /// <summary>
        /// Initializes a new instance of the <see cref="OrganizationService"/> class.
        /// </summary>
        public OrganizationService()
        {
            this._repository = DependenceInjectionContainer.Resolve<IOrganizationRepository>();
        }

        /// <summary>
        /// Gets all department.
        /// </summary>
        /// <returns></returns>
        public List<Department> GetAllDepartment()
        {
            return this._repository.GetAllDepartment();
        }

        /// <summary>
        /// Creates the department.
        /// </summary>
        /// <param name="department">The department.</param>
        /// <returns></returns>
        public Department CreateDepartment(Department department)
        {
            ValidationResult result = Validation.CheckDepartment(department);

            if (result.IsCorrect)
            {
                return this._repository.CreateDepartment(department);
            }
            else
            {
                throw new Exception(result.Message);
            }
        }

        public Employee CreateEmployee(Employee employeeDto)
        {
            ValidationResult result = Validation.CheckEmployee(employeeDto);

            if (result.IsCorrect)
            {
            return this._repository.CreateEmployee(employeeDto);
            }
            else
            {
                throw new Exception(result.Message);
            }
        }

        public  DataTable SelectEmployeeLevel()
        {
           return  _repository.SelectEmployeeLevel();
        
        }

        public DataTable SelectEmployeeTitle()
        {
            return _repository.SelectEmployeeTitle();
        }

        public DataTable SelectEmployeeDirector()
        {
            return _repository.SelectEmployeeDirector();
        }
    }
}
